package Test.trycatch;

/**
 * @ClassName Test02
 * @since: 2023/9/2 10:12
 * @auth: kirito
 * @description:
 **/
public class Demo01  {
    public static void main(String[] args) {
        System.out.println(func());
    }
//    finally块在return语句执行之后，return语句返回之前执行
    public static int func() {
        int a = 10;
        try {
            System.out.println("try中的代码块");
            a += 10;
            return a;
        } catch (Exception e) {
            System.out.println("catch中的代码块");
        } finally {
            System.out.println("finally中的代码块");
            a += 10;
            if (a > 10) {
                System.out.println("a > 10," + "a=" + a);
            }
            a += 10;
        }
        System.out.println("haha");//如果catch中添加了【return a += 1000;】，这里会报错：Unreachable statement
        return a;
    }

}
